import java.lang.reflect.Array;
import java.util.Arrays;

public class Test2 {
    public static void main(String[] args) {
        int[] A = new int[6];
        A[0]=1;
        A[1]=2;
        A[2]=3;
        int[] B = {5,6,7};
//        int m = A.length;
//        int n = B.length;
        merge(A,3,B,3);
        System.out.println(Arrays.toString(A));
    }
    public static void merge(int[] A,int m,int[] B,int n){
        int i = m-1;
        int j = n-1;
        int k = m+n-1;
        while(i>=0 && j>=0){
            if (A[i] >= B[j]){
                A[k] = A[i];
                k--;
                i--;
            }else{
                A[k] = B[j];
                k--;
                j--;
            }
        }
        while(i>=0){
            A[k] = A[i];
            k--;
            i--;
        }
        while(j>=0){
            A[k] = B[j];
            k--;
            j--;
        }
    }
}
